name: Verify Docs Quality
on:
  pull_request:
    branches: [master]
    paths:
      - '.github/workflows/verify_docs-quality.yml'
      - '**.md'

jobs:
  check-all-files:
    runs-on: ubuntu-latest

    steps:
      - name: Harden Runner
        uses: step-security/harden-runner@63c24ba6bd7ba022e95695ff85de572c04a18142 # v2.7.0
        with:
          egress-policy: audit

      - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

      # Vale does not support file excludes, so we use the script to generate a list of files instead
      # The action also does not allow args or a local config file to be passed in, so the files array
      # also contains an "--config=.github/vale/config.ini" option
      - name: generate vale args
        id: generate
        run: echo "args=$(node scripts/check-docs-quality.js --ci-args)" >> $GITHUB_OUTPUT

      - name: documentation quality check
        uses: errata-ai/vale-action@38bf078c328061f59879b347ca344a718a736018 # v2.1.0
        with:
          # This also contains --config=.github/vale/config.ini ... :/
          files: '${{ steps.generate.outputs.args }}'
          version: latest
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
